<?php
class shopadminControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
	 
		$this->smarty->assign(array(
			"data"=>M("login")->getShopAdmin()
		));
		$this->smarty->display("shopadmin/add.html");
	}
	
	public function onSave(){
		$data['adminname']=$adminname=post('adminname','h');
		if(empty($data['adminname'])){
			$this->goAll("账号名称不能为空",1);
		}
		if(post('password')){
				if(post('password')!=post('password2')) $this->goall("两次密码输入不一致",1);
				$data["salt"]=rand(1000,9999);
				$data["password"]=umd5(post("password","h").$data["salt"]);
				
		}
		$data['telephone']=post('telephone','h');
		$row=M("shopadmin")->selectRow("adminname='".$adminname."'");
		
		if($row && $row['adminid']!=$_SESSION['ssshopadmin']['adminid']){
			$this->goall("账号已经存在",1);
		}
		
		
		M("shopadmin")->update($data,"adminid=".$_SESSION['ssshopadmin']['adminid']);
		$this->goall("修改成功",0);
	}
}
?>